<?php
/**
 * @Name: PhoneNumber.php
 * @Author: yashuai 1762910894@qq.com
 */

namespace HugCode\WeChat\Miniprogram;

use HugCode\WeChat\Basics\BasicWeChat;
use HugCode\WeChat\Basics\HttpRequest;
use HugCode\WeChat\Basics\Exception\MessageException;

class PhoneNumber extends BasicWeChat
{

    const CODE_GET_USER_PHONE = 'wxa/business/getuserphonenumber'; // code换取用户手机号


    /**
     * @Desc code换取用户手机号
     * @param string $code
     * @return mixed|string
     * @throws MessageException
     * @author yashuai 1762910894@qq.com
     */
    public function getUserPhoneNumber(string $code)
    {
        $data        = [
            'code' => $code,
        ];
        $request_url = self::API_BASE_URL_PREFIX . self::CODE_GET_USER_PHONE . '?access_token=' . $this->access_token;
        return HttpRequest::instance()->post($request_url, json_encode($data))->toArray();
    }

}
